﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Xml;
using System.Xml.Linq;
using Yonkly.Models;
using Yonkly.Services;
using Yonkly.Utility;
using Yonkly.Views;
using JsonResult = System.Web.Mvc.JsonResult;

namespace Yonkly.Controllers
{
    public class HomeController : BaseController
    {
        public ActionResult Index()
        {
            if (IsUserAuthenticated)
            {
                return RedirectToAction("View", "User", new { Username = User.Identity.Name });
                //new RouteValueDictionary(
                //    new
                //        {
                //            Controller = "User",
                //            Action = "View",
                //            Username = User.Identity.Name 
                //        }));
            }
            else
            {
                return RedirectToAction("View", "Timeline");
            }
        }

        //public ActionResult TwitterImport()
        //{
        //    var t = new Twitter();
        //    var j = t.GetUserTimeline("xxx", "xxxx", "eibrahim", Twitter.OutputFormatType.XML);

        //    TextReader tr = new StringReader(j);

        //    var doc = XDocument.Load(tr);
        //    IEnumerable<TwitterStatus> q = from status in doc.Descendants("status")
        //                                   select new TwitterStatus()
        //                                              {
        //                                                  Text = status.Element("text").Value,
        //                                                  Source = status.Element("source").Value,
        //                                                  Id = Convert.ToInt64(status.Element("id").Value),
        //                                                  CreatedAt = status.Element("created_at").Value,
        //                                                  Favorited = status.Element("favorited").Value
        //                                              };

        //    BaseViewData data = GetBaseViewData();
        //    ViewData["temp"] = j;// q.ToList();
        //    ViewData["tweets"] = q;
        //    return View(data);
        //}

        //public JsonResult TwitterGetStatuses()
        //{
        //    var t = new Twitter();
        //    return Json(t.GetUserTimeline("xxx", "xxx", "eibrahim", Twitter.OutputFormatType.JSON));

        //}

        public ActionResult Error()
        {
            return View("Error", GetBaseViewData());
        }

    }
}
